﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using MyStore.PresentationModel.Models.Products;
using MyStore.Products;

namespace MyStore.PresentationModel.Controllers
{
    public class ProductController : Controller
    {
        private readonly IProductService productService;
        public ProductController(IProductService productService)
        {
            this.productService = productService;
        }

        public ActionResult List()
        {
            var results = new List<ProductOnSaleModel>();
            var products = productService.GetNewProduct(0, 20);

            products.ToList<Product>().ForEach(p =>
            {
                var item = new ProductOnSaleModel { Code = p.Code, Name = p.Name };
                item.Price = 10.4m;
                results.Add(item);
            });

            return View(results);
        }

        public ActionResult Detail(string code)
        {
            ProductDetailModel product = new ProductDetailModel();
            if (code == "111111")
            {
                product = new ProductDetailModel
               {
                   Code = "111111",
                   Name = "C++编程珠玑",
                   Price = 19.5m,
                   Author = "chenjz",
                   Introduction = "一本介绍c++编程的书",
                   Image = "http://images.99read.com/newProduct/431/170.170/c0000360278.jpg"
               };
            }

            if (code == "123456")
            {
                product = new ProductDetailModel
                {
                    Code = "123456",
                    Name = "他的国",
                    Price = 59m,
                    Author = "韩寒",
                    Introduction = @"在你年少时是否曾梦想成为国王？长大后的你是否还会继续这个英雄梦？有些人的心里没有很多东西，哪怕是穿过内心的深处挖到肝里也没有。有没有比兄弟和女人更加重要的情谊？有没有比飙车时凛冽的风更刺激的逃亡？纵身跳下，恍惚里终于看见一双双惊讶和肯定的眼神。画面在人们面前晃过，你的青春是否也只是果园里一块不和谐的石头？这是一个关于他的国的故事。野草冲出土壤，它们一百三十五度仰望的天空在哪里…",
                    Image = "http://images.99read.com/newProduct/200/170.170/c0000196425.jpg"
                };
            }
            return View(product);
        }

        public ActionResult newitem()
        {
            return Content("Test");
        }
    }
}
